/***************************************************************************
*  Clientview.h
*
*  July 2007
*  Copyright  2007  RuijinZheng,China
*  Email mebetop@126.com
****************************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
#include <QPalette>
#include <QSizePolicy>
#include "Clientview.h"
ClientView::ClientView(QWidget *parent ,Qt::WindowFlags f){
	widget=new QWidget(parent,f);
	layout=new QVBoxLayout(widget);
	this->setWidget(widget);
	this->viewport()->setBackgroundRole(QPalette::Dark);
	this->viewport()->setAutoFillBackground(true); 
	this->length=20;
	this->width=880;
    
}
ClientView::~ClientView(){
/*	ClientElement *ele;
	while(!clientList.empty()){
		ele=clientList.back();
		clientList.pop_back();
		delete ele;
	}
*/  // alert.don't do	it !
}
void ClientView::resizeWidget(int w,int h){
	widget->resize(w,h);
}
void ClientView::addClientToWidget(const AbstractClientElement& ele){
	ClientElement *client=new ClientElement(0,0,ele);
	clientList.push_back(client);
	layout->addWidget((QWidget *)client);
	this->length+=52;
	resizeWidget(this->width,this->length);
}
void ClientView::delClientFromWidget(const pid_t &pid){
	Pidlist::iterator iterator=clientList.begin();
	while(iterator!=clientList.end()){
		if((*iterator)->getPid()==pid){
			layout->removeWidget(*iterator);
			
			delete *iterator;
			this->length-=52;
			resizeWidget(this->width,this->length);
			break;
		}
		iterator++;
	}
}
